package com.briup.product_my.controller;

import com.briup.product_my.domain.ManagerFenceHouse;
import com.briup.product_my.domain.ManagerHurdles;
import com.briup.product_my.domain.ext.ManagerFenceHouseExt;
import com.briup.product_my.result.Result;
import com.briup.product_my.service.HurdlesService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: xiongwenbin
 * @Date: 2024/8/22-08-22-上午10:35
 * @Description: com.briup.product_my.controller
 */
@Api(tags = "栏圈管理模块")
@RestController

@RequestMapping("/hurdle")
public class HurdlesController {
    @Autowired
    private HurdlesService hurdlesService;

    @ApiOperation(value = "查询所有的栏圈容量")
    @GetMapping("/queryAllMax")
    public Result queryAllMax() {
        return Result.success(hurdlesService.queryAllMax());
    }

    @ApiOperation(value = "分⻚+条件查询栏圈")
    @GetMapping()
    public Result selectAllBy(@RequestParam(value = "pageNum") Integer pageNum,@RequestParam(value = "pageSize") Integer pageSize,@RequestParam(value = "hName",required = false) String hName,@RequestParam(value = "hMax",required = false) Integer hMax,@RequestParam(value = "fhName",required = false) String fhName,@RequestParam(value = "hEnable",required = false) String hEnable) {
        PageInfo<ManagerFenceHouseExt> result = hurdlesService.selectAllBy(pageNum,pageSize,hName,hMax,fhName,hEnable);
        return Result.success(result);
    }


    @ApiOperation(value = "根据栏圈编号禁⽤/启⽤栏圈")
    @PutMapping("/{hId}/{hEnable}")
    public Result updateEnable(@PathVariable("hId") String hId, @PathVariable("hEnable") String hEnable) {
        hurdlesService.updateEnable(hId,hEnable);
        return Result.success();
    }
    @ApiOperation(value = "根据栏圈编号批量禁⽤/启⽤栏圈")
    @PutMapping
    public Result updateEnableBatch(@RequestBody List<ManagerHurdles> managerHurdles) {
        hurdlesService.updateEnableBatch(managerHurdles);
        return Result.success();
    }
    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "保存或修改栏圈")
    public Result saveOrUpdate(@RequestBody ManagerHurdles managerHurdles) {

        return Result.success(hurdlesService.saveOrUpdate(managerHurdles));
    }
    @DeleteMapping("/deleteById/{hId}")
    @ApiOperation(value = "根据栏圈编号删除栏圈")

    public Result deleteById(@PathVariable("hId") String hId) {
        hurdlesService.deleteById(hId);
        return Result.success();
    }

    @GetMapping("/queryAllEnable")
    @ApiOperation(value = "查询所有启用的栏圈")
    public Result queryAllEnable() {
        return Result.success(hurdlesService.queryAllEnable());
    }
}
